<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>03_JS数据类型</title>
</head>
<body>
<script>
    //JS数据类型 = 原始类型 + 引用类型
    //原始类型：number string boolean null undefined
    var a = 1;
    var b = 9.9; //整数小数都是number类型
    console.log(a,typeof a,b,typeof b);
    var c = 'hello';
    var d = 'world'; //单引号双引号都是string类型
    console.log(c,typeof c,d,typeof d);
    var e = true;
    var f = false; //true与false都是boolean类型
    console.log(e,typeof e,f,typeof f);
    var g; //声明了变量单位复制，值为undeefined，未定义型
    console.log(g,typeof g); //undefined 'undefined'

    //引用类型 Array Object  Function Date。。。
    let obj ={};
    console.log(obj,typeof obj); //{} 'object'
    obj.name = '张三';
    obj.age = 18;
    console.log(obj,typeof obj); //{name: '张三', age: 18} 'object'
    console.log(obj.name);
    console.log(obj.age);

    //自定义对象的写法2
    let obj2 = {
        name:'张三',
        age:18
    };
    console.log(obj2,typeof obj2); //{name: '张三', age: 18} 'object'
    console.log(obj2.name);
    console.log(obj2.age);
    console.log(obj2.like);//访问对象不存在的属性会得到undefined

    //数组
    let arr = [1,2,3,4,5];
    console.log(arr,typeof arr);
    console.log(arr[0]);
    console.log(arr[1]);
    console.log(arr[2]);
    console.log(arr[3]);
    console.log(arr[99]);//访问数组不存在的元素也会得到undefined

    //Number()将参数转化为数值类型，如果无法得到数字类型的结果，则返回NaN（Not a Number）
    console.log(Number(true),typeof Number(true));//1,number
    console.log(Number(false));//0,number
    console.log(Number('3'));//3
    console.log(Number(3));//3
    console.log(Number('6.6'));//6.6
    console.log(Number('哈哈哈'));//NaN

    //Boolean()将参数转化为布尔类型，如果参数为0、null、undefined、""，则返回false，其他参数返回true
    console.log(Boolean(0));//false
    console.log(Boolean(null));//false
    console.log(Boolean(undefined));//false
    console.log(Boolean(NaN));//false
    console.log(Boolean(''));//false
    console.log(Boolean(' '));//true
    console.log(Boolean('哈哈'));//true
    console.log(Boolean(1));//true
    console.log(Boolean('1'));//true
</script>
</body>
</html>